home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / tools / nwtp06 / tstbind.pas < prev    next >
Pascal/Delphi Source File  |  1996-07-10  |  9KB  |  249 lines

  1. {$X+,B-,V-,S-} {essential compiler directives}
  2.  
  3. Program TSTBin; { as of 950301 }
  4.  
  5. { Testprogram for the nwBindry unit / NwTP 0.6 API. (c) 1994,1995 R.Spronk }
  6.  
  7. { Purpose: Testing only. }
  8.  
  9. { Tests the following nwBindry calls:
  10.  
  11.   AddBinderyObjectToSet
  12.   ChangeBinderyObjectSecurity
  13.   ChangeBinderyObjectPassword
  14.   ChangeEncrBinderyObjectPassword
  15.   ChangePropertySecurity
  16.   CreateBinderyObject
  17.   CreateProperty
  18.   DeleteBinderyObject
  19.   DeleteBinderyObjectFromSet
  20.   DeleteProperty
  21.   GetBinderyAccessLevel
  22.   GetBinderyObjectID
  23.   GetBinderyObjectName
  24.   IsBinderyObjectInSet
  25.   RenameBinderyObject
  26.   VerifyBinderyObjectPassword
  27.   VerifyEncrBinderyObjectPassword
  28.   WritePropertyValue
  29. }
  30.  
  31. Uses nwMisc,nwBindry;
  32.  
  33. Procedure Warning(mess:string);
  34. begin
  35. writeln(' ERROR:',mess);
  36. writeln(' ERROR#: $',hexstr(result,2),'  (',result,')');
  37. end;
  38.  
  39.  
  40. Function ExistsProperty(objName:string;objType:word;propertyName:String):boolean;
  41.  
  42. Var propName:string;
  43.     pf,ps   :byte;
  44.     phv,mp  :boolean;
  45.     seqNbr  :LongInt;
  46. begin
  47. seqNbr:=-1;
  48. ExistsProperty:=ScanProperty(objName,objType,propertyname,
  49.                              seqNbr,propName,pf,ps,phv,mp);
  50. end;
  51.  
  52.  
  53. Var myObjId:longInt;
  54.     BindSeq:Byte;
  55.  
  56.     ObjId    :longint;
  57.     usrName,TrueName:string;
  58.     pTrueName:Tproperty;
  59.  
  60.     replyUsrName:string;
  61.     replyObjType:word;
  62.  
  63.     t:byte;
  64.     s:string;
  65.  
  66. begin
  67. writeln('BINTEST Test program for the nwBindry unit of the NwTP package.');
  68.  
  69. IF not IsShellLoaded
  70.  then begin
  71.       writeln('Please load shell before running.');
  72.       halt(1);
  73.       end;
  74. { need supervisor privileges to run this test }
  75. GetBinderyAccessLevel(BindSeq,myObjId);
  76. if bindSeq<>(BS_SUPER_WRITE OR BS_SUPER_READ) { $33}
  77.  then begin
  78.       writeln('you need to be supervisor equivalent to run this test program.');
  79.       halt(1);
  80.       end;
  81.  
  82. writeln('-Assumes there is a group ''EVERYONE''');
  83. writeln('-Non destructive to the bindery. ');
  84. writeln(' (unless you already have a user named ''USR_OINK'' or ''THE_DIVA'')');
  85. writeln;
  86. writeln('For testing of the  unencrypted calls, you must have');
  87. writeln(' SET ALLOW UNENCRYPTED PASSWORDS=ON on the server--');
  88. writeln(' Otherwise these calls will fail and trigger the servers'' intruder detection.');
  89. writeln;
  90. writeln('<ENTER> To Continue..');
  91. readln;
  92.  
  93. { you are reminded that the bindery functions turn all object names, property
  94.   names and passwords to upcase. Returned strings are also upcase. }
  95.  
  96. usrName:='UsR_OiNk';
  97. TrueName:='Miss Piggy';
  98.  
  99. writeln('Creating Bindery object :',usrName);
  100. IF NOT CreateBinderyObject(usrName,OT_USER,
  101.                            BF_ITEM,BS_ANY_READ OR BS_ANY_WRITE)
  102.  then Warning('couldn''t create a bindery object.');
  103.  
  104. IF NOT GetBinderyObjectID(usrName,OT_USER,objID)
  105.  then Warning('couldn''t find the created user object');
  106.  
  107. writeln('Changing object security.');
  108. IF NOT ChangeBinderyObjectSecurity(usrName,OT_USER,BS_LOGGED_READ OR BS_SUPER_WRITE)
  109.  then warning('Couldn''t change object security.');
  110.  
  111. { this program assumes there is a group called everyone. }
  112. writeln('Making ',usrName,' a member of the group EVERYONE.');
  113. IF IsBinderyObjectInSet(usrName,OT_USER,
  114.                         'GROUP_MEMBERS','EVERYONE',OT_USER_GROUP)
  115.  then writeln('??: object already is a member of everyone (group)');
  116.  
  117. IF NOT AddBinderyObjectToSet('EVERYONE',OT_USER_GROUP,'GROUP_MEMBERS',
  118.                               usrName,OT_USER)
  119.  then Warning('couldn''t make user a member of everyone');
  120.  
  121. IF NOT IsBinderyObjectInSet('EVERYONE',OT_USER_GROUP,'GROUP_MEMBERS',
  122.                         usrName,OT_USER)
  123.  then writeln('??: user is NOT a member of everyone.');
  124.  
  125.  
  126. { ------------AND NOW: the property test.
  127.   create a static property with default security... }
  128. writeln;
  129. writeln('Creating a property IDENTIFICATION associated withe the ',usrName,' object.');
  130. IF NOT CreateProperty(usrName,OT_USER,
  131.                       'IDENTIFICATION',BF_ITEM,BS_ANY_WRITE OR BS_ANY_READ)
  132.  then writeln('Couldn''t create property.');
  133.  
  134. IF NOT ChangePropertySecurity(usrName,OT_USER,'IDENTIFICATION',
  135.                               BS_LOGGED_READ or BS_SUPER_WRITE)
  136.  then writeln('Couldn''t change property security.');
  137.  
  138. writeln('Writing the property value: ',trueName);
  139. FillChar(pTrueName[1],SizeOf(pTrueName),#0);
  140. for t:=1 to ord(truename[0]) do pTrueName[t]:=ord(TrueName[t]);
  141.  
  142. IF NOT WritePropertyValue(usrName,OT_USER,'IDENTIFICATION',1,pTrueName,FALSE)
  143.  then Warning('Couldn''t write the property value.');
  144.  
  145. { The next calls were tested before, so they are not tested again.
  146.   They create the minimal properties needed to login as the new object. }
  147.  
  148. CreateProperty(usrName,OT_USER,'GROUPS_I''M_IN',
  149.                BF_SET,BS_SUPER_WRITE OR BS_LOGGED_READ);
  150.  
  151. AddBinderyObjectToSet(usrName,OT_USER,'GROUPS_I''M_IN',
  152.                       'EVERYONE',OT_USER_GROUP);
  153.  
  154. CreateProperty(usrName,OT_USER,'SECURITY_EQUALS',
  155.                BF_SET,BS_SUPER_WRITE OR BS_LOGGED_READ);
  156.  
  157. AddBinderyObjectToSet(usrName,OT_USER,'SECURITY_EQUALS',
  158.                       'EVERYONE',OT_USER_GROUP);
  159.  
  160. {------------- Renaming the object. }
  161. writeln;
  162. writeln('Renaming the object.');
  163. UpString(usrName); { make usrName upstring for comparison with found name.}
  164.  
  165. GetBinderyObjectName(objId,replyUsrName,replyObjType);
  166. IF (nwBindry.result>0) or (replyUsrName<>usrName) or (replyObjType<>OT_USER)
  167.  then Warning('Something very wrong here.');
  168. writeln(' Object name was   :',replyUsrName);
  169.  
  170. IF NOT RenameBinderyObject(usrName,'THE_DIVA',OT_USER)
  171.  then Warning('Couldn''t rename the object.');
  172.  
  173. usrName:='THE_DIVA'; {that's what it should be now}
  174.  
  175. GetBinderyObjectName(objId,replyUsrName,replyObjType);
  176. IF (nwBindry.result<>0) or (replyUsrName<>usrName) or (replyObjType<>OT_USER)
  177.  then Warning('Object was NOT renamed.');
  178. writeln(' Object name now is:',replyUsrName);
  179.  
  180. {------------ Change and verify bindery object password. }
  181.  
  182. writeln;
  183. writeln('Changing Object Password. (encrypted)');
  184. IF ChangeEncrBinderyObjectPassword(usrName,OT_USER,'','KERMIT')
  185.  then writeln('Password successfully changed. (encrypted)')
  186.  else Warning('Couldn''t change password. (encrypted)');
  187.  
  188. writeln('Verifying new password. (encrypted)');
  189. IF VerifyEncrBinderyObjectPassword(usrName,OT_USER,'wrong password')
  190.  then Warning('A wrong (encrypted) password was verified as being OK.');
  191.  
  192. IF NOT VerifyEncrBinderyObjectPassword(usrName,OT_USER,'KERMIT')
  193.  then Warning('The correct (encrypted) Password was NOT verified.');
  194.  
  195. { If you stop execution of this program AT THIS POINT, you will
  196.   have added a user THE_DIVA with password KERMIT, member of the
  197.   group EVERYONE to your bindery. }
  198.  
  199. { halt(0); }
  200.  
  201. writeln;
  202. writeln('WARNING: If you didn''t SET ALLOW UNENCRYPTED PASSWORDS=ON,');
  203. writeln('         -The server will beep;');
  204. writeln('         -Supervisor(s) will receive a 1 line message.');
  205. writeln('          (unless CASTOFF ALL was used);');
  206. writeln('         -The next(unencrypted) calls will fail.');
  207. writeln('         (All the above is essentially harmless)');
  208. writeln;
  209. writeln(' <ENTER> to continue...');
  210. readln;
  211.  
  212. writeln;
  213. writeln('Changing Object Password. (unencrypted)');
  214. IF ChangeBinderyObjectPassword(usrName,OT_USER,'KERMIT','SECRET')
  215.  then writeln('Password successfully changed. (unencrypted)')
  216.  else Warning('Couldn''t change password. (unencrypted)');
  217.  
  218. writeln('Verifying new password. (unencrypted)');
  219. IF VerifyBinderyObjectPassword(usrName,OT_USER,'wrong password')
  220.  then Warning('A wrong (unencrypted) password was verified as being OK.');
  221.  
  222. IF NOT VerifyBinderyObjectPassword(usrName,OT_USER,'SECRET')
  223.  then Warning('The correct (unencrypted) Password was NOT verified.');
  224.  
  225. {------------ Deleting  properties and objects }
  226. writeln;
  227. writeln('Deleting a property.');
  228. IF NOT DeleteProperty(usrName,OT_USER,'IDENTIFICATION')
  229.  then writeln('Couldn''t delete property.');
  230.  
  231. IF ExistsProperty(usrName,OT_USER,'IDENTIFICATION')
  232.  then writeln('??:Property wasn''t deleted.');
  233.  
  234. writeln('Removing the user object from the group EVERYONE.');
  235. DeleteBinderyObjectFromSet(usrName,OT_USER,
  236.                            'GROUP_MEMBERS','EVERYONE',OT_USER_GROUP);
  237.  
  238. IF IsBinderyObjectInSet(usrName,OT_USER,
  239.                         'GROUP_MEMBERS','EVERYONE',OT_USER_GROUP)
  240.  then writeln('Couldn''t throw '+usrName+' out of everyone (group)');
  241.  
  242. writeln('Deleting the ',usrName,' object and all related properties.');
  243. IF NOT DeleteBinderyObject(usrName,OT_USER)
  244.  then writeln('Couldn''t delete object.');
  245.  
  246. IF GetBinderyObjectID(usrName,OT_USER,objID)
  247.  then writeln('??: deleted object still exists.');
  248.  
  249. end.